package core.gamemodes;

import java.awt.Point;

import core.Player;
import core.PlayerData;
import core.SingleButtonGame;
import core.mountedWeapons.GenericPistol;
import core.units.HeroUnit;
import core.units.Unit;

public abstract class GameMode {
	SingleButtonGame main;
	public String name;
	public String forcedMap;
	protected int playerCounter=0;
	protected Player AI;
	
	public GameMode(SingleButtonGame m){
		main=m;
	}
	public void initConfiguration(){
		
	}
	public void initGame(){
		
	}
	public void onFrameLogic(){
		
	}
	public void setupPlayerData(PlayerData d){
		Unit u = new HeroUnit(0, 0, null);
		u.addWeapon(new GenericPistol(20, 70));
		d.addUnit(u);
		d.selectNextUnit();		
	}
	/**
	 * Uses given data to create and spawn a player to the map.
	 * @param data
	 */
	public void createPlayer(PlayerData data){
		Point spawnPoint = main.map.getSpawnPoint(playerCounter);
		int playersPerRow = 8;
		int spinXPos = 135*(playerCounter%playersPerRow)+80;
		int spinYPos = 70+playerCounter/playersPerRow*135;
		Player addedPlayer = new Player(spinXPos, spinYPos, playerCounter, data.getKey(), spawnPoint, main);
		addedPlayer.setPlayerData(data);
		main.players.add(addedPlayer);
		addedPlayer.toMainSpinner();
		addedPlayer.spawnFirstUnit();
		additionalPlayerSetup(addedPlayer);
		
		playerCounter++;
	}
	/**
	 * Called at game initiation for each player.
	 * Specific for each gameMode
	 */
	protected void additionalPlayerSetup(Player p){
		
	}
	public void setupAI(){
		
	}
	public String getName(){
		return name;
	}
	public boolean victoryCheck(){
		return false;
	}
}